package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.goods.wxbean.CategoryVO;
import com.cskaoyan.bean.goods.wxbean.GoodsDetailVO;
import com.cskaoyan.mapper.goodsMapper.MarketGoodsMapper;
import com.cskaoyan.service.WXSearchService;
import com.cskaoyan.service.wxgoods_service.WXGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Hu
 * @create 2021-09-18 14:04
 * @Description
 */


@RestController
@RequestMapping("wx/goods")
public class WXGoodsController {

    @Autowired
    WXGoodsService wxGoodsService;

    @Autowired
    WXSearchService wxSearchService;

    //传入id显示详情信息 有无库存?count?
    @RequestMapping("detail")
    public BaseRespVo detail(Integer id) {
        GoodsDetailVO result = wxGoodsService.detail(id);
        return BaseRespVo.ok(result);
    }

    @RequestMapping("related")
    public BaseRespVo related(Integer id) {
        BaseData baseData = wxGoodsService.related(id);
        return BaseRespVo.ok(baseData);

    }

    @RequestMapping("count")
    public BaseRespVo count() {
        Integer count = wxGoodsService.count();
        return BaseRespVo.ok(count);
    }


    @RequestMapping("category")
    public BaseRespVo category(Integer id) {
        CategoryVO result =  wxGoodsService.category(id);
        return BaseRespVo.ok(result);
    }


    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam ,Integer categoryId, Integer brandId, String keyword, Boolean isHot, Boolean isNew) {

        if (keyword==null&&isHot==null&&isNew==null) {
            BaseData result =  wxGoodsService.list(baseParam,categoryId,brandId);
            return BaseRespVo.ok(result);
        }else {
            BaseRespVo result = wxSearchService.result(baseParam, categoryId, brandId, keyword, isHot, isNew);
            return BaseRespVo.ok(result);
        }
    }







}
